package cn.yuanqiao.web.controller.archive.detection;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.appManager.domain.TenantMdataList;

import cn.yuanqiao.archive.detection.domain.Detection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.detection.domain.DetectionScheme;
import cn.yuanqiao.archive.detection.service.IDetectionSchemeService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 四性检测方案Controller
 * 
 * @author xy
 * @date 2023-08-07
 */
@RestController
@RequestMapping("/archive/detectionScheme")
public class DetectionSchemeController extends BaseController
{
    @Autowired
    private IDetectionSchemeService detectionSchemeService;


    /**
     * 查询四性检测方案列表
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:list')")
*/
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('archive:fourNatures:detectionPlan:list')")
    public TableDataInfo list(DetectionScheme detectionScheme)
    {
        startPage();
        List<DetectionScheme> list = detectionSchemeService.selectDetectionSchemeListByRole(detectionScheme);
        return getDataTable(list);
    }
    @GetMapping("/getList")
    public TableDataInfo getList(DetectionScheme detectionScheme)
    {
/*
        startPage();
*/
        List<DetectionScheme> list = detectionSchemeService.selectDetectionSchemeList(detectionScheme);
        return getDataTable(list);
    }

    /**
     * 导出四性检测方案列表
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:export')")
*/
    @Log(title = "四性检测方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DetectionScheme detectionScheme)
    {
        List<DetectionScheme> list = detectionSchemeService.selectDetectionSchemeList(detectionScheme);
        ExcelUtil<DetectionScheme> util = new ExcelUtil<DetectionScheme>(DetectionScheme.class);
        util.exportExcel(response, list, "四性检测方案数据");
    }

    /**
     * 获取四性检测方案详细信息
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:query')")
*/
    @PreAuthorize("@ss.hasPermi('archive:fourNatures:detectionPlan:programme')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(detectionSchemeService.selectDetectionSchemeById(id));
    }

    /**
     * 新增四性检测方案
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:add')")
*/
    @PreAuthorize("@ss.hasPermi('archive:fourNatures:detectionPlan:add')")
    @Log(title = "四性检测方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DetectionScheme detectionScheme)
    {

        return toAjax(detectionSchemeService.insertDetectionScheme(detectionScheme));
    }

    /**
     * 修改四性检测方案
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:edit')")
*/
    @PreAuthorize("@ss.hasPermi('archive:fourNatures:detectionPlan:edit')")
    @Log(title = "四性检测方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DetectionScheme detectionScheme)
    {
        return toAjax(detectionSchemeService.updateDetectionScheme(detectionScheme));
    }

    /**
     * 删除四性检测方案
     */
/*
    @PreAuthorize("@ss.hasPermi('archive:DetectionScheme:remove')")
*/
    @PreAuthorize("@ss.hasPermi('archive:fourNatures:detectionPlan:delete')")
    @Log(title = "四性检测方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(detectionSchemeService.deleteDetectionSchemeByIds(ids));
    }

    //获取元数据
    @GetMapping("/getSchemelist")
    public TableDataInfo getSchemelist(TenantMdataList yqdaMdataList)
    {
        List<TenantMdataList> list = detectionSchemeService.getNewSchemelist(yqdaMdataList);
        return getDataTable(list);
    }

    //获取方案配置
    @GetMapping("/tree")
    public AjaxResult tree(String code)
    {

        List<Detection> treeSelects = detectionSchemeService.selectTreeList(code);
        return success(treeSelects);
    }
    //获取档号规则
    @GetMapping("/getDh")
   public AjaxResult getDh(Long categoryId,String type){
        List dh=detectionSchemeService.getDhList(categoryId,type);
        return success(dh);
   }

    //获取方案配置
    @GetMapping("/objectTree")
    public AjaxResult objectTree(Long id,String code)
    {
          //0 归档 1:移交 2:长期

        List<Detection> treeSelects = detectionSchemeService.objectTree(id,code);
        return success(treeSelects);
    }

}
